/*
 * p1267.cpp
 *
 *  Created on: 2013-10-24
 *      Author: zy
 */
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;
const int maxn = 1010;
vector<int> son[maxn], nodes[maxn];
int n, s, k, fa[maxn];
bool covered[maxn];

void dfs(int u, int f, int dep)
{
	fa[u] = f;
	if (son[u].size() == 1 && dep > k)
		nodes[dep].push_back(u);
	for (int i = 0; i < son[u].size(); i++)
	{
		int v = son[u][i];
		if (v != f)
			dfs(v, u, dep + 1);
	}
}

void dfs2(int u, int f, int dep)
{
	covered[u] = true;
	for (int i = 0; i < son[u].size(); i++)
	{
		int v = son[u][i];
		if (v != f && dep < k)
			dfs2(v, u, dep + 1);
	}
}
int solve()
{
	int ans = 0;
	memset(covered, 0, sizeof(covered));
	for (int d = n - 1; d > k; d--)
		for (int i = 0; i < nodes[d].size(); i++)
		{
			int u = nodes[d][i];
			if (covered[u])
				continue;

			int v = u;
			for (int j = 0; j < k; j++)
				v = fa[v];
			dfs2(v, -1, 0);
			ans++;
		}
	return ans;
}
int main()
{
	int T;
	scanf("%d", &T);
	while (T--)
	{
		scanf("%d%d%d", &n, &s, &k);
		for (int i = 1; i <= n; i++)
		{
			son[i].clear();
			nodes[i].clear();
		}
		for (int i = 0; i < n - 1; i++)
		{
			int a, b;
			scanf("%d%d", &a, &b);
			son[a].push_back(b);
			son[b].push_back(a);
		}
		dfs(s, -1, 0);
		printf("%d\n", solve());
	}
	return 0;
}
